package onlinejudge.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import onlinejudge.dao.CommunityDao;
import onlinejudge.entity.Community;
import onlinejudge.service.CommunityService;
import onlinejudge.util.DateUtil;
import onlinejudge.vo.CommunityVo;

@Service
public class CommunityServiceImpl implements CommunityService {
	
	@Resource
	private CommunityDao communityDao;
	private Map<String, Object> parameters=new HashMap<String, Object>();
	
	@Override
	public List<CommunityVo> queryCommunity(Map<String, Object> parameters1) {
		return communityDao.queryCommunity(parameters1);
	}
	
	@Override
	public void addCommunity(Community community) {
		parameters.clear();
		parameters.put("userId", community.getUserId());
		parameters.put("itemTitle", community.getItemTitle());
		parameters.put("itemContent", community.getItemContent());
		parameters.put("itemDate", CommunityCommentServiceImpl.javaDateUtil.getDateTime());
		parameters.put("itemCount", 0);
		communityDao.addCommunity(parameters);
	}
	
	@Override
	public void updateCommunity(Community community) {
		parameters.clear();
		parameters.put("communityId", community.getCommunityId());
		parameters.put("itemCount", community.getItemCount());
		communityDao.updateCommunity(parameters);
	}
	
	@Override
	public void deleteCommunity(Integer communityId) {
		communityDao.deleteCommunity(communityId);
	}

	@Override
	public Integer getCommunityCount() {
		parameters.clear();
		return communityDao.queryCommunity(parameters).size();
	}
}
